package org.compression.controller;

import org.compression.constant.Constant;
import org.compression.mapper.AccessIPStatMapper;
import org.model.auth.AccessIPStat;
import org.model.comm.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ip")
public class IpManagerController{
		
	
	@Autowired
	AccessIPStatMapper mAccessIPStatMapper;
	
	
	@RequestMapping(value="getIps",method = RequestMethod.POST)
	public Object getIps(@RequestBody Page mAccessIPStat) {
		System.out.println(mAccessIPStat.getCurrentPageNum()+" "+mAccessIPStat.getPageSize());
		return mAccessIPStatMapper.getPageIps(mAccessIPStat);
	}
	
	
	@RequestMapping(value="insert",method = RequestMethod.POST)
	public Object insert(@RequestBody AccessIPStat mAccessIPStat) {
		 mAccessIPStatMapper.insert(mAccessIPStat);
		 Constant.ips.add(mAccessIPStat.getIpAddr());
		 return mAccessIPStatMapper.getIps();
	}
	
	@RequestMapping(value="deleteByPrimaryKey",method = RequestMethod.DELETE)
	public Object deleteByPrimaryKey(@RequestBody AccessIPStat mAccessIPStat) {
		 mAccessIPStatMapper.deleteByPrimaryKey(mAccessIPStat.getId());
		 Constant.ips.remove(mAccessIPStat.getIpAddr());
		 return mAccessIPStatMapper.getIps();
	}
	
	
	
	
	
	
	
}
